//
//  UIImageView+AG.swift
//  AG
//
//  Created by zhuxuhong on 2020/10/28.
//  Copyright © 2020 AgoCulture. All rights reserved.
//

import BWToolKit
import Kingfisher

extension UIImageView {
    public func bw_loadImage(
        _ url: String?,
        placeholderImage: UIImage? = nil,
        completion: BlockTT<UIImage?, Error?>? = nil
    ) {
        guard let url = url, let aURL = URL(string: url) else {
            return
        }
        KF.url(aURL)
            .loadDiskFileSynchronously()
            .placeholder(placeholderImage)
            .transition(.fade(0.25))
            .onFailure{ completion?(nil, $0) }
            .onSuccess { completion?($0.image, nil) }
            .set(to: self)
    }
}
